package com.sunday.aomicaichang.adpter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sunday.aomicaichang.R;
import com.sunday.aomicaichang.model.Wallet;

import java.math.BigDecimal;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yun_sheng on 2017/6/6.
 */

public class WalletDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<Wallet> wallets;

    public WalletDetailAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setmData(List<Wallet> wallets) {
        this.wallets = wallets;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_wallet_detail, parent, false);
        return new ItemViewHolder1(v);

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Wallet wallet = wallets.get(position);
        ItemViewHolder1 viewHolder = (ItemViewHolder1) holder;
        viewHolder.price.setText(wallet.getAmount()+"");
        if(wallet.getRemark()!=null)
        viewHolder.number.setText(wallet.getRemark());
        if(wallet.getTypeStr()!=null)
        viewHolder.type.setText(wallet.getTypeStr());
        if(wallet.getCreateDate()!=null)
        viewHolder.time.setText(wallet.getCreateDate());
        if(wallet.getAmount().compareTo(new BigDecimal("0.00"))<0){
            viewHolder.price.setTextColor(ContextCompat.getColor(mContext,R.color._ed6d00));
        }else {
            viewHolder.price.setTextColor(ContextCompat.getColor(mContext,R.color._666));
        }
    }

    @Override
    public int getItemCount() {
        return wallets == null ? 0 : wallets.size();
    }

    public class ItemViewHolder1 extends RecyclerView.ViewHolder {
        @Bind(R.id.price)
        TextView price;
        @Bind(R.id.type)
        TextView type;
        @Bind(R.id.number)
        TextView number;
        @Bind(R.id.time)
        TextView time;

        public ItemViewHolder1(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
